package com.ruoyi.system.utils;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Date;

import org.springframework.web.multipart.MultipartFile;

import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSException;

public class ALiYunFileHelper {
	
	//参数 
	public static final String endPoint = "oss-cn-beijing.aliyuncs.com";
	public static final String accessKeyId = "5Jii89BFukxmun5j";
	public static final String accessKeySecret = "JvE9FcILlHu5gClmAJr89ZkEv00l9s";
	public static final String bucketName = "yjlive160322";
	public static final String folder = "mall/images/";
	public static final String bucketURL = "https://flower-mall.oss-cn-shanghai.aliyuncs.com/";
	
	 
	
	//参数 
	/*public static final String endPoint = "oss-cn-shanghai.aliyuncs.com";
	public static final String accessKeyId = "LTAIqaxMt899NWaN";
	public static final String accessKeySecret = "cY0opzcG7i0C8vt4pbxuD8PkbHtgFD";
	public static final String bucketName = "edu-cation";
	public static final String folder = "devimg/image/";
	public static final String bucketURL = "https://edu-cation.oss-cn-shanghai.aliyuncs.com/";*/
	/**
	 * 文件上传，
	 * 
	 * @param uploadFile
	 * @return 文件路径
	 */
	public static String picOSS(MultipartFile uploadFile) {
		//log.info("上传的图片名： " + uploadFile.getName());
		String str = "";
		// 创建实例
		OSSClient ossClient = new OSSClient(endPoint, accessKeyId,
				accessKeySecret,"");
		long time = new Date().getTime();
		// 上传
		try {
			ossClient.putObject(bucketName, folder + time + uploadFile.getOriginalFilename(),
					new ByteArrayInputStream(uploadFile.getBytes()));
			// 关闭client
			ossClient.shutdown();
			// 正式上线后的文件夹路径
			str = folder + time + uploadFile.getOriginalFilename();
			//log.info(str);
			return bucketURL + str;
		} catch (OSSException | ClientException | IOException e) {
			e.printStackTrace();
			return "上传失败";
		}
	}

}
